//
//  SIXStatus.m
//  weibo
//
//  Created by chenangel on 16/5/21.
//  Copyright © 2016年 chuhan. All rights reserved.
//

#import "SIXStatus.h"

#import "NSDate+Extension.h"
#import "SIXPhoto.h"

@class SIXPhoto;
@implementation SIXStatus
+ (NSDictionary *)mj_objectClassInArray{
    return @{@"pic_urls" : [SIXPhoto class]};

}

- (NSString *)created_at
{
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

    fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
    
    // 微博的创建日期
    NSDate *createDate = [fmt dateFromString:_created_at];
    // 当前时间
    NSDate *now = [NSDate date];
    
    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    // 计算两个日期之间的差值
    NSDateComponents *cmps = [calendar components:unit fromDate:createDate toDate:now options:0];
    
    if ([createDate isThisYear]) { // 今年
        if ([createDate isYesterday]) { // 昨天
            fmt.dateFormat = @"昨天 HH:mm";
            return [fmt stringFromDate:createDate];
        } else if ([createDate isToday]) { // 今天
            if (cmps.hour >= 1) {
                return [NSString stringWithFormat:@"%d小时前", (int)cmps.hour];
            } else if (cmps.minute >= 1) {
                return [NSString stringWithFormat:@"%d分钟前", (int)cmps.minute];
            } else {
                return @"刚刚";
            }
        } else { // 今年的其他日子
            fmt.dateFormat = @"MM-dd HH:mm";
            return [fmt stringFromDate:createDate];
        }
    } else { // 非今年
        fmt.dateFormat = @"yyyy-MM-dd HH:mm";
        return [fmt stringFromDate:createDate];
    }
}
//<a href="http://app.weibo.com/t/feed/4AbAFV" rel="nofollow">微话题</a>
- (void)setSource:(NSString *)source
{
    if (source.length > 5) {
    //    SIXLog(@"%@",source);
        NSArray *arr = [source componentsSeparatedByString:@"</"];
        NSString *str = arr[0];
        NSArray *arr1 = [str componentsSeparatedByString:@">"];
       //SIXLog(@"来源----%@---%@",arr1[0],arr1[1]);
        _source = [NSString stringWithFormat:@"来自-%@",arr1[1]];
    }else{
        _source = @"";
    }
    
}
@end
